package com.bugbuff.dubbo.server.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.bugbuff.common.mapper.UserMapper;
import com.bugbuff.common.pojo.User;
import io.jsonwebtoken.Jwts;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class UserService {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Autowired
    private UserMapper userMapper;



    /**
     * 业务层实现功能:退出登录
     *
     */
    public void logoutBsUser(String token) {
        //将用户的token的缓存数据删除掉,用户就无法通过token校验登录
        redisTemplate.delete(token);
    }

    /**
     * 根据指定时间获取user对象
     * @param startTime
     * @param endTime
     * @return
     */
    public Integer queryUserByTime(Date startTime, Date endTime) {

        QueryWrapper<User> queryWrapper1 = new QueryWrapper<>();
        /*queryWrapper1.gt("created", startTime);
        queryWrapper1.lt("created", endTime);*/
        queryWrapper1.between("created",startTime,endTime);
        return this.userMapper.selectCount(queryWrapper1);
    }

    public List<User> queryUserListByTime(Date startTime, Date endTime){

        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.gt("created", startTime);
        queryWrapper.lt("created", endTime);

        //新注册的用户
        return this.userMapper.selectList(queryWrapper);
    }
}
